package com.mrent.util;

import java.util.Calendar;
import java.util.logging.Logger;

import org.apache.commons.lang.RandomStringUtils;

import com.mrent.service.OrderManagerServiceImpl;

public class Utils {
	
	private static java.util.logging.Logger logger = Logger.getLogger(Utils.class.getName());
	
	/**
	 * 构造日期时间串.
	 * 
	 * @return
	 */
	public static String generDataNo(){
		Calendar calendar = Calendar.getInstance();
		StringBuilder sb =  new StringBuilder();
		synchronized(calendar){
			int year	= calendar.get(Calendar.YEAR);
	        int month	= calendar.get(Calendar.MONTH)+1;
	        int day		= calendar.get(Calendar.DATE);
	        int hours	= calendar.get(Calendar.HOUR);
	        int minute	= calendar.get(Calendar.MINUTE);
	        int seconds	= calendar.get(Calendar.SECOND);
	        sb.append(year);
	        if(month >= 10){
	        	sb.append(month);
	        }else{
	        	sb.append("0"+month);
	        }
	        if(day >= 10){
	        	sb.append(day);
	        }else{
	        	sb.append("0"+day);
	        }
	        if(hours >= 10){
	        	sb.append(hours);
	        }else{
	        	sb.append("0"+hours);
	        }
	        if(minute >= 10){
	        	sb.append(minute);
	        }else{
	        	sb.append("0"+minute);
	        }
	        if(seconds >= 10){
	        	sb.append(seconds);
	        }else{
	        	sb.append("0"+seconds);
	        }
	        return sb.toString() + RandomStringUtils.randomNumeric(6);        
		}
	}
	
	/**
	 * 订单申请日期比较.
	 * 
	 * @param calendar
	 * @param dbcalendar
	 * @return
	 */
	public static boolean orderCalendarComp(Calendar calendarstart,Calendar calendarend,Calendar dbcalendarstart,Calendar dbcalendarend){
		boolean OK = true;
		//只有开店日期和到期日期均早于或迟于数据库存在的开店日期与到期日期.
		if(calendarstart.before(dbcalendarstart) && calendarend.before(dbcalendarstart)){
			OK = false;
		}
		if(calendarstart.after(dbcalendarend) && calendarend.after(dbcalendarend)){
			OK = false;
		}
		return OK;
	}
	
	/**
	 * 订单店主日期比较.
	 * 
	 * @param calendar
	 * @param dbcalendarstart
	 * @param dbcalendarend
	 * @return
	 */
	public static boolean orderManagerCalendarComp(Calendar calendar,Calendar dbcalendarstart,Calendar dbcalendarend){
		boolean OK = false;
		logger.info("calendar.compareTo(dbcalendarstart)=" + calendar.compareTo(dbcalendarstart));
		if(calendar.compareTo(dbcalendarstart) ==0 ){
			logger.info("==start");
			OK = true;
		}
		logger.info("calendar.compareTo(dbcalendarend)=" + calendar.compareTo(dbcalendarend));
		if(calendar.compareTo(dbcalendarend) == 0){
			logger.info("==end");
			OK = true;
		}
		logger.info(new Boolean(calendar.after(dbcalendarstart)).toString());
		logger.info(new Boolean(calendar.before(dbcalendarend)).toString());
		if(calendar.after(dbcalendarstart) && calendar.before(dbcalendarend)){
			logger.info("==between");
			OK = true;
		}
		logger.info("OK=" + OK);
		return OK;
	}

}
